﻿const workorderFormRules = {
	customerId: [{
		required: true,
		message: '请选择客户公司名称',
		trigger: 'blur'
	}],
	leaderId: [{
		required: true,
		message: '请选择财税负责人',
		trigger: 'blur'
	}],
	enddate: [{
		required: true,
		message: '请选择截止日期',
		trigger: 'blur'
	}],
	remake: [{
		required: true,
		message: '请填写备注',
		trigger: 'blur'
	}],
	chargerId: [{
		required: true,
		message: "事项负责人不能为空",
		trigger: "blur"
	}]

};
const customerFormrules = {
	compname: [{
		required: true,
		message: '请输入客户名称',
		trigger: 'blur'
	}],
	contacter: [{
		required: true,
		message: '请输入联系人姓名',
		trigger: 'blur'
	}],
	contractNumber: [{
		required: true,
		message: '请输入联系人电话',
		trigger: 'blur'
	}],

	taxtype: [{
		required: true,
		message: '请选择税务类型',
		trigger: 'blur'
	}]
};
const TOOLBAR = [{
		content: "添加",
		icon: "el-icon-document-add",
		type: "primary"
	},
	{
		content: "删除",
		icon: "el-icon-document-remove",
		type: "danger"
	}
];
const COLUMNS = [
    {
		prop: "id",
		label: "工单号",
		width: "80"
	},
    {
		prop: "transdate",
		label: "流转日期",
		width: "100"
	},
	{
		prop: "contractNumber",
		label: "合同号",
		width: "80"
	},
	{
		prop: "documentNumber",
		label: "档案号",
		width: "80"
	},
	{
		prop: "taxGroupName",
		label: "财税分组",
		width: "80"
	},
	{
		prop: "compname",
		label: "公司名称",
		width: "160"
	},

	{
		prop: "contacter",
		label: "联系人",
		width: "80"
	},
	{
		prop: "phone",
		label: "电话",
		width: "130"
	},
	{
		prop: "taxtype",
		label: "税务类型",
		width: "100"
	},
	{
		prop: "name",
		label: "服务名称",
		width: "80"
	},
	{
		prop: "matter",
		label: "事项",
		width: "80"
	},
	{
		prop: "status",
		label: "状态",
		width: "80"
	},
	{
		prop: "leader",
		label: "主管",
		width: "80"
	},
	{
		prop: "remake",
		label: "备注",
		width: "80"
	},
	{
		prop: "enddate",
		label: "截止日期",
		width: "100"
	},
	{
		prop: "updateTime",
		label: "更新日期",
		width: "100"
	}
];
const PCOLUMNS = [{
		prop: "username",
		label: "姓名",
		width: "40"
	}

];
const transFormrules = {
	contractNumber: [{
		required: true,
		message: '请选择合同号',
		trigger: 'blur'
	}],
	documentNumber: [{
		required: true,
		message: '请选择档案号',
		trigger: 'blur'
	}],
	taxGroup: [{
		required: true,
		message: '请选择财税分组',
		trigger: 'blur'
	}],
	enddate: [{
		required: true,
		message: '请选择服务到期时间',
		trigger: 'blur'
	}],
	leaderId: [{
		required: true,
		message: '请选择工商负责人名字',
		trigger: 'blur'
	}]
}
const workorderDetailFormrules = {
	matter: [{
		required: true,
		message: '请选择事项',
		trigger: 'blur'
	}],
	status: [{
		required: true,
		message: '请选择状态',
		trigger: 'blur'
	}],
	endTime: [{
		required: true,
		message: '请选择截止日期',
		trigger: 'blur'
	}],
	chargerId: [{
		required: true,
		message: '请选择事项负责人',
		trigger: 'blur'
	}],
	remake: [{
		required: true,
		message: '请填写备注',
		trigger: 'blur'
	}]
}
const serviceFormDetailRules = {
	name: [{
		required: true,
		message: '请选择服务名称',
		trigger: 'blur'
	}],
	time: [{
		required: true,
		message: '请输入时限',
		trigger: 'blur'
	}],
	amount: [{
		required: true,
		message: '请输入数量',
		trigger: 'blur'
	}],
	unit: [{
		required: true,
		message: '请输入单位',
		trigger: 'blur'
	}],
	cost: [{
		required: true,
		message: '请输入成本金额',
		trigger: 'blur'
	}],
	price: [{
		required: true,
		message: '请输入单价',
		trigger: 'blur'
	}],
	totalprice: [{
		required: true,
		message: '请输入服务金额',
		trigger: 'blur'
	}]
};
let app = new Vue({
	el: "#app",
	data() {
		return {
			serviceFormDetail: {
				id: 0,
				serviceId: 0,
				name: "",
				spec: "",
				type: "",
				amount: 0,
				unit: "",
				cost: 0,
				price: 0,
				totalprice: 0,
				memo: "",
				service: []
			},
			detailcolums: [{
					"prop": "id",
					"label": "编号",
					"width": "100"
				},
				{
					"prop": "name",
					"label": "名称",
					"width": "100"
				},
				{
					"prop": "spec",
					"label": "规格",
					"width": "80"
				},
				{
					"prop": "type",
					"label": "类别",
					"width": "80"
				},
				{
					"prop": "unit",
					"label": "单位",
					"width": "50"
				},
			
				{
					"prop": "price",
					"label": "单价",
					"width": "100"
				},
				{
					"prop": "amount",
					"label": "数量",
					"width": "50"
				},
				{
					"prop": "totalprice",
					"label": "收款金额",
					"width": "100"
				},
				{
					"prop": "cost",
					"label": "成本金额",
					"width": "100"
				},
				{
					"prop": "items",
					"label": "服务项目",
					"width": "80"
				},
				{
					"prop": "memo",
					"label": "备注",
					"width": "80"
				}
			],
			distridetailcolums: [{
				"prop": "name",
				"label": "事项名称",
				"width": "80"
			}],
			serviceForm: {
				id: null,
				mycustomerid: null,
				customerid: null,
				compname: "",
				legalperson: "",
				contacter: "",
				phone: "",
				address: "",
				area: "",
				status: "",
				business: "",
				collectiondate: "",
				transdate: "",
				treasurer: "",
				supervisor: "",
				sellerid: "",
				sellername: "",
				outformerid: "",
				outformername: "",
				src: "",
				signtype: "",
				addresstype: "",
				invoicingtype: "",
				amountinvoicing: "",
				taxtype: "",
				gifts: "",
				paytype: "",
				service: [],
				amounttotal: 0,
				amountreceivables: "",
				amountpayin: "",
				amountend: "",
				amountendcondition: "",
				financeid: "",
				financename: "",
				financestatus: "",
				materials: [],
				annex: [],
				handoverid: "",
				handovername: "",
				handoverstatus: "",
				receiverid: "",
				receivername: "",
				receiverstatus: "",
				supervisorid: "",
				supervisorname: "",
				supervisorstatus: "",
				costerid: "",
				costername: "",
				costerstatus: "",
				memo: ""
			},
			customerForm: {

			},
			options: [],
			value: [],
			list: [],
			addBusinessShow: true,
			dialogserviceFormDetailVisible: false,
			loading: false,
			timestamp: new Date().getTime(),
			uploadurl: axios.defaults.baseURL + "api/workorderdetailform/annex/upload/",
			headers: {
				Token: localStorage.getItem('TOKEN'),
				UserID: localStorage.getItem('USERID')
			},
			fileList: [],
			services: [],
			submitDisable: false,
			imgdialogImageUrl: "",
			submitEditDisable: false,
			imgdialogVisible: false,
			dialogEditBaseFormVisible: false,
			dialogDocFormVisible: false,
			docsrc:'',
			combinationForm: {
				defaultProps: {
					children: 'children',
					label: 'label'
				},

			},
			stateoptions: STATETYPE,
			teamLink: "i am copy",
			leftbar_show: true,
			// 添加、编辑标识
			action: "",
			dialogEditFormVisible: false,
			dialogItemFormVisible: false,
			dialogFormVisible:false,
			tableHeight: window.innerHeight - 180,
			toolbar: TOOLBAR,
			tablecolums: COLUMNS,
			tabvalue: "base",
			workorderForm:{},
			queryForm: {
				keyword: "",
				taxtype: "",
				name: "",
				matter: "",
				status: "",
				charger: "",
				servicename: "",
				endTime: [],
				transdate: [],
				updateTime: [],
				pageNo: 1, // 当前页码
				pagesize: 100, // 每页记录数
				pagesizes: [10, 20, 50, 100]
			},
			transForm: {

			},
			workorderDetailForm: {

			},
			pagepersontotal: 0,
			pagepersontotaltemp: 0,
			pagetotal: 0,
			pagetotaltemp: 0,
			pickerOptions: {
				shortcuts: [{
					text: '最近一周',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近一个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近三个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
						picker.$emit('pick', [start, end]);
					}
				}]
			},
			//税务类型
			taxtypeoptions: TAXTYPEOPTIONS,
			//状态
			status: WORKORDERSTATUS,
			// 所有部门
			depts:[],
			//员工
			allusers: [],
			//员工
			members: [],
			//服务名称
			servicenames: [],
			//待办事项
			handleitems: [],
			//所有待办事项
			allhandleitems: [],
			// 多选
			multipleSelection: [],
			pagedatatemp: [], // 当前页结果集
			pagedata: [], // 当前页结果集
			pagepersondatatemp: [], // 当前页用户结果集
			pagepersondata: [], // 当前页用户结果集
			loaded: false,
		}
	},
	methods: {
		//服务相关
		
		
		// 添加服务
		addService() {
			this.action = "adddetail";
			this.dialogserviceFormDetailVisible = true
			this.serviceFormDetail.id = 0
			this.serviceFormDetail.serviceId = 0
			this.serviceFormDetail.name = ""
			this.serviceFormDetail.amount = 0
			this.serviceFormDetail.unit = ""
			this.serviceFormDetail.cost = 0
			this.serviceFormDetail.price = 0
			this.serviceFormDetail.totalprice = 0
			this.serviceFormDetail.memo = ""
			this.serviceFormDetail.service = []
		},
		// 编辑服务
		editService(index, row) {
			this.action = "editdetail"
			this.dindex = index;
			this.dialogserviceFormDetailVisible = true
			this.serviceFormDetail = deepCopy(row)
		},
		// 删除服务
		delService(index, row) {
			this.serviceForm.service.splice(index, 1)
			this.workorderForm.recs.splice(index, 1)
			if (this.workorderForm.recs.length == 0) {
				this.addBusinessShow = true
			}
		},
		// 服务项目变化时
		async servicechange(id) {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
		
				let res = await axios.get('api/servicedetail/get/' + id);
				if (res.code === 200) {
					this.serviceFormDetail.service = res.data;
					if (this.serviceFormDetail.service.length > 0) {
						this.serviceFormDetail.amount = 1
						this.serviceFormDetail.serviceId = id
						this.serviceFormDetail.id = this.serviceFormDetail.service[0].id
						this.serviceFormDetail.name = this.serviceFormDetail.service[0].name
						this.serviceFormDetail.price = this.serviceFormDetail.service[0].price
						this.serviceFormDetail.totalprice = this.serviceFormDetail.service[0].price * this.serviceFormDetail.amount
						this.serviceFormDetail.unit = this.serviceFormDetail.service[0].unit
						this.serviceFormDetail.spec = this.serviceFormDetail.service[0].spec
						this.serviceFormDetail.type = this.serviceFormDetail.service[0].type
		
						this.serviceFormDetail.cost = this.serviceFormDetail.service[0].cost * this.serviceFormDetail.amount
						this.serviceFormDetail.items = this.serviceFormDetail.service[0].items
						this.serviceFormDetail.memo = this.serviceFormDetail.service[0].memo
					} else {
						this.serviceFormDetail.serviceId = 0
						this.serviceFormDetail.id = 0
						this.serviceFormDetail.amount = 1
						this.serviceFormDetail.name = this.serviceFormDetail.name
						this.serviceFormDetail.price = 0
						this.serviceFormDetail.totalprice = 0
						this.serviceFormDetail.unit = "无"
						this.serviceFormDetail.spec = "无"
						this.serviceFormDetail.type = "无"
						this.serviceFormDetail.cost = 0
						this.serviceFormDetail.items = ""
						this.serviceFormDetail.memo = ""
					}
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('服务项目请求出错！', e.message);
			}
		
			// 关闭加载框
			loading.close();
		},
		
		docshow(index, row) {
			this.action = "docshow"
			this.index = index;
			this.dialogDocFormVisible = true;
			this.customerForm = deepCopy(row)
			this.docsrc = "../service/uploadframe.html?docnumber=" + this.customerForm.documentNumber
		},
		editbase(index, row) {
			this.action = "editbase"
			this.index = index;
			this.dialogEditBaseFormVisible = true;
			this.customerForm = deepCopy(row)
		},
		async editbaseconfirm() {
			this.$refs.customerForm.validate(async valid => {
				if (valid) {
					const loading = this.$loading(LOAD_STYLE);
					try {
						let res = await axios.put('api/keepaccount/editcus', this.customerForm);
						if (res.code === 200) {
							this.dialogEditBaseFormVisible = false
							this.query()
							this.$message.success(res.message);
						} else {
							this.$message.error(res.message);
						}
					} catch (e) {
						this.$message.error('请求出错！', e.message);
					}
					// 关闭加载框
					loading.close();
				}
			})
		},		
		async querycustomer(query) {
		
			try {
				let res = await axios.get('api/keepaccount/querycustomer/' + query);
		
				if (res.code === 200) {
					this.list = res.data
					//this.$message.success(res.message);
				} else {
					//this.$message.error(res.message);
				}
			} catch (e) {
				//this.$message.error('请求出错！', e.message);
			}
		
		
		},
		remoteMethod(query) {
			if (query.length > 3) {
				this.querycustomer(query)
			}
			if (query !== '') {
				this.loading = true;
				setTimeout(() => {
					this.loading = false;
					this.options = this.list.filter(item => {
						return item.label.toLowerCase()
							.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.options = [];
			}
		},
		//删除
		async removeitem() {
			try {
				let res = await axios.post('api/workorder/removeitem', this.workorderDetailForm);
				if (res.code === 200) {
					this.query();
					this.$message({
						type: 'success',
						message: '删除成功!'
					});
				} else {
					this.$message.error(res.message);
				}

			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}

		},
		//删除
		remove(index, row) {
			this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.workorderDetailForm = deepCopy(row)
				this.removeitem()

			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});
			});
		},
		additem(index, row) {
			console.log(row)
			this.action = "additem"
			this.index = index;
			this.dialogItemFormVisible = true;
			this.fileList = [];
			this.workorderDetailForm = {
				workorderId: row.id,
				charger: "",
				chargerId: null,
				matter: "",
				status: "",
				endTime: "",
				leader: "",
				remake: "",
				evidence: []
			}
			this.initCondition(row.name)
		},
		edititem(index, row) {
			this.action = "edititem"
			this.dialogItemFormVisible = true;
			console.log(row)
			this.initCondition(row.name)
			this.workorderDetailForm = deepCopy(row)
			
			this.fileList = this.workorderDetailForm.evidence
			for (item in this.workorderDetailForm.evidence) {
				this.fileList[item].url = DOWNLOAD_PATH + "/" + this.workorderDetailForm.workorderId + "/" + this.workorderDetailForm
					.id + "/" + this.workorderDetailForm.evidence[item].name + "/" + localStorage.getItem('TOKEN')
			}
			this.createTempfilelist(this.fileList)
		},
		async itemcofirm() {
			this.submitDisable = true;
			this.$refs.workorderDetailForm.validate(async valid => {
				if (valid) {

					const loading = this.$loading(LOAD_STYLE);
					try {
						let res = null;
						if (this.action == "additem") {
							//添加
							res = await axios.post('api/workorder/additem', this.workorderDetailForm);
						} else if (this.action == "edititem") {
							//编辑
							res = await axios.put('api/workorder/edititem', this.workorderDetailForm);
						}

						if (res.code === 200) {
							this.dialogItemFormVisible = false
							this.query()
							this.$message.success(res.message);
						} else {
							this.$message.error(res.message);
						}
					} catch (e) {
						this.$message.error('请求出错！', e.message);
					}
					// 关闭加载框
					loading.close();
				}
			})
			this.submitDisable = false;
		},
		edit(index, row) {
			this.action = "edit"
			row.taxGroup = row.taxGroup==0?null:row.taxGroup
			this.index = index;
			this.dialogEditFormVisible = true;
			this.transForm = deepCopy(row)

		},
		async editcofirm() {
			this.submitEditDisable = true;
			this.$refs.transForm.validate(async valid => {
				if (valid) {
					// 显示加载框
					const loading = this.$loading(LOAD_STYLE);
					try {
						let res = await axios.put('api/workorder/edit', this.transForm);
						if (res.code === 200) {
							this.dialogEditFormVisible = false
							this.query()
							this.$message.success(res.message);
						} else {
							this.$message.error(res.message);
						}
					} catch (e) {
						this.$message.error('请求出错！', e.message);
					}
					// 关闭加载框
					loading.close();
				}
			})
			this.submitEditDisable = false;
		},
		// 初始化团队成员列表
		async initMembers() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/team/member/' + localStorage.getItem('USERID'));
				if (res.code === 200) {
					this.members = res.data;
					if (this.members.length > 0) {

					}
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
		},
		async initHandleItem() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/service/handleitem');
				if (res.code === 200) {
					this.allhandleitems = res.data;
					if (this.allhandleitems.length > 0) {

					}
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();

		},
		// 取得事项
		async getmatter() {
		this.initCondition(this.queryForm.name)
		},
		async initServiceName() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/service/servicename');
				if (res.code === 200) {
					this.servicenames = res.data;
					console.log(this.servicenames)
					if (this.servicenames.length > 0) {

					}
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
		},
		// 取得所有部门列表
		async getAllDept() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/alldept');
				if (res.code === 200) {
					this.depts = res.data;
				}else {
					this.$message.error(res.message);
				}
			}catch (e) {
				this.$message.error('请求出错！', e.message);
			}
			
			// 关闭加载框
			loading.close();
		},
		clickTable(row, expandedRows) {
			console.log(row)
			console.log(expandedRows)
		},
		// 取得组织结构
		async getCombination() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/detp/combination');
				if (res.code === 200) {
					this.combinationForm.data = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('组织结构请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
		},

		toolAction(acName) {
			console.log(acName)
			if (acName == "删除") {
				this.removeconfirm();
			}else if (acName == "添加") {
				this.addconfirm();
			}
		},
		addconfirm() {
					this.action = "add";
					this.dialogFormVisible = true;
					this.workorderForm = {
						enddate: "",
						name: "",
						servicedetailId: null,
						leaderId: null,
						remake: "",
						recs: [],		
						customerId: null
					}
					this.serviceForm.service=[]
					this.addBusinessShow = true
				},
		removeconfirm() {
			if (this.multipleSelection.length > 0) {
				if (true) {
					this.$confirm('选择行中有多条数据，确定要将数据删除吗?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(async () => {
						this.removemul()
					}).catch((e) => {
						this.$message({
							type: 'info',
							message: '已取消删除'
						});
					});
				} else {

				}
			} else {
				this.$message.error('请选择数据行！');
			}
		},
		async getAllUser() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/user/all');
				if (res.code === 200) {
					this.allusers = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('取得所有用户列表请求出错！', e.message);
			}
		
			// 关闭加载框
			loading.close();
		
		},
		async removemul() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let ids = []
				for (let row of this.multipleSelection) {
					ids.push(row.id)
				}
				console.log(ids)
				let param = {
					"ids": ids
				}
				let res = await axios.post('api/workorder/removemul', param);
				if (res.code === 200) {
					this.$message.success(res.message);
					this.query();
					//this.dialogAssigneFormVisible = false
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}
			// 关闭加载框
			loading.close();
		},
		// 显示侧边栏
		showLeftBar() {

			if (this.leftbar_show)
				return this.leftbar_show = false
			if (!this.leftbar_show)
				return this.leftbar_show = true

		},
		// 表格多选 
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},


		// 检查数据是否有修改
		checkDataChanged() {
			// 比对数据有无发生变化
			for (let key in this.testpaperForm) {
				if (this.testpaperForm[key] != this.testpaperFormOrg[key]) {
					return true;
				}
			}
			return false;
		},

		start() {
			this.queryForm.pageNo = 1
			this.query()
		},

		// 查询
		async query() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.post('api/workorder/querylist', this.queryForm);
				if (res.code === 200) {
					this.pagedata = res.data;
					this.pagetotal = res.total;
					this.$message.success(res.message);
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}
			// 关闭加载框
			loading.close();
		},
		initCondition(servicename) {
			for (serviceindex in this.servicenames) {
				if ((this.servicenames[serviceindex].name) == servicename) {
					serviceId = this.servicenames[serviceindex].id
				}else{
					serviceId =0
				}
			}
			temp = []
			for (handleindex in this.allhandleitems) {
				if (serviceId == this.allhandleitems[handleindex].service_id) {
					temp.push(
						Object.assign(this.allhandleitems[handleindex])
					)
				}
			}
			this.handleitems = temp
		},


		selectionChange(selection) {
			this.selection = selection
		},



		// 设定表格当前页
		handleCurrentPageChange(selectedPageNo) {
			this.queryForm.pageNo = selectedPageNo
			// 加载数据页
			this.query()
		},
		//设定每页记录数
		handleSizeChange(val) {
			this.queryForm.pagesize = val
			// 加载数据页
			this.query()
		},
		// 设定表格当前页
		handlePersonCurrentPageChange(selectedPageNo) {
			this.queryPersonForm.pageNo = selectedPageNo
			// 加载数据页
			this.queryPerson()
		},
		//设定每页记录数
		handlePersonSizeChange(val) {
			this.queryPersonForm.pagesize = val
			// 加载数据页
			this.queryPerson()
		},
		handleRemove(file, fileList) {

			this.createTempfilelist(fileList);
		},
		handledownloadPreview(file) {
			console.log(file)
			this.imgdialogImageUrl = file.url;
			this.imgdialogVisible = true;
		},
		//upload系列
		handleAvatarSuccess(res, file, filelist) {
			this.createTempfilelist(filelist);
		},
		beforeAvatarUpload(file) {
			const isJPG = ["image/jpeg", "image/jpg", "image/png"].indexOf(file.type) > -1;
			const isLt2M = file.size / 1024 / 1024 < 2;
			if (!isJPG) {
				this.$message.error('图片只能是png,jpeg,jpg格式!');
				return false;
			}
			if (!isLt2M) {
				this.$message.error('上传图片大小不能超过 2MB!');
				return false;
			}
			return true;
		},
		createTempfilelist(filelist) {
			console.log(filelist)
			this.tempfilelist = []
			for (let s of filelist) {
				if (typeof(s.response) != "undefined") {
					this.tempfilelist.push({
						//name: s.response.data.name,
						url: "",
						name: s.name,
					});
				} else {
					this.tempfilelist.push({
						url: "",
						name: s.name,
					});
				}
				this.workorderDetailForm.evidence = this.tempfilelist
			}
		},
		//工单新增确认提交
		workorderconfirm() {
			console.log(this.workorderForm)
			this.$refs.workorderForm.validate(async valid => {
				if ((valid)&(this.workorderForm.recs.length!=0)) {
					// 显示加载框
					const loading = this.$loading(LOAD_STYLE);
					try {
						// 外部工单录入确认
						let res = await axios.post('api/workorder/add', this.workorderForm);
						if (res.code === 200) {
							this.$message.success(res.message);
							this.query();
							this.dialogFormVisible = false
						} else {
							this.$message.error(res.message);
						}
					} catch (e) {
						this.$message.error('添加出错！', e.message);
					}
					//关闭加载框
					loading.close();
		
		
				} else {
					if (this.workorderForm.recs.length == 0) {
						this.$message.error('请在选择业务中添加服务项目');
						this.tabvalue = 'base'
					} else if (this.workorderForm.recs.length > 1) {
						this.$message.error('请在办理业务中删除服务项目，只能选择一个');
						this.tabvalue = 'base'
					} else {
						this.$message.error('请确认基础信息*号项目都以填写。');
					}
				}
			})
		
		},
		// 确认添加，编辑服务信息
		confirmService() {
			this.$refs.serviceFormDetail.validate(async valid => {
				if (valid) {
					let res = null;
					if (this.action == "adddetail") {
						// 添加服务
						this.serviceForm.service.push(deepCopy(this.serviceFormDetail))
						this.workorderForm.recs.push(deepCopy(this.serviceFormDetail))
					} else if (this.action == "editdetail") {
						// 编辑服务
						this.serviceForm.service[this.dindex].amount = this.serviceFormDetail.amount
						this.serviceForm.service[this.dindex].totalprice = this.serviceFormDetail.totalprice
						this.serviceForm.service[this.dindex].name = this.serviceFormDetail.name
						this.serviceForm.service[this.dindex].unit = this.serviceFormDetail.unit
						this.serviceForm.service[this.dindex].time = this.serviceFormDetail.time
						this.serviceForm.service[this.dindex].cost = this.serviceFormDetail.cost
						this.serviceForm.service[this.dindex].price = this.serviceFormDetail.price
						this.workorderForm.recs[this.dindex].price = this.serviceFormDetail.price
					}
					if (this.workorderForm.recs.length > 0) {
						this.addBusinessShow = false
					}
					this.workorderForm.servicedetailId = this.workorderForm.recs[0].id
					this.workorderForm.name = this.workorderForm.recs[0].name
					this.workorderForm.unit = this.workorderForm.recs[0].unit
					this.workorderForm.amount = this.workorderForm.recs[0].amount
					this.dialogserviceFormDetailVisible = false
				} else {
		
				}
			})
		},
		serviceDetailClick(row, column, event) {
			this.serviceFormDetail.id = row.id
			this.serviceFormDetail.amount = 1
			this.serviceFormDetail.name = row.name
			this.serviceFormDetail.price = row.price
			this.serviceFormDetail.unit = row.unit
			this.serviceFormDetail.spec = row.spec
			this.serviceFormDetail.type = row.type
			this.serviceFormDetail.cost = row.cost
			this.serviceFormDetail.items = row.items
			this.serviceFormDetail.memo = row.memo
		},
		// 取得所有服务项目
		async getService() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/service/get');
				if (res.code === 200) {
					this.services = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('服务项目请求出错！', e.message);
			}
			var result = this.services.filter(function(item) {
				return item.name != AGENTKEEPNAME
			});
			for (var i = 0; i < result.length; i++) {
				//	console.log(result[i]);
		
			}
			this.services = result
		
			// 关闭加载框
			loading.close();
		},
		
		
	},
	async mounted() {
		// 自动调整表格高度
		window.onresize = () => {
				return (() => {
					this.tableHeight = window.innerHeight - 180
				})()
			},
			// 取得服务列表
			this.getService();
			//初始化部门列表
			this.getAllDept();
		//初始组织结构
		this.getCombination()
		//初始化员工列表
		this.getAllUser();
		//初始化员工列表
		this.initMembers();
		//初始化服务名称
		await this.initServiceName();
		//初始化待办理事项
		//await this.initHandleItem();
	}

});
